﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Quexcel.OpenXML.Transaction;
using Quexcel.OpenXML.Excel.Worksheet.Components;

namespace Quexcel.OpenXML
{
    public class ExcelHelper
    {
        public static void ExecuteNonQuery(string connectionString, string commandText)
        {
            using (ExcelConnection connection = new ExcelConnection(connectionString))
            {
                connection.Open();
                ExecuteNonQuery(connection, commandText);
            }
        }

        public static void ExecuteNonQuery(ExcelConnection connection, string commandText)
        {
            ExcelCommand command = new ExcelCommand(connection, commandText);
            ExecuteNonQuery(command);
        }

        public static void ExecuteNonQuery(ExcelTransaction transaction, string commandText)
        {
            ExcelCommand command = new ExcelCommand(transaction, commandText);
            ExecuteNonQuery(command);
        }

        public static void ExecuteNonQuery(ExcelCommand command)
        {
            command.ExecuteNonQuery();
        }


        public static IEnumerator<Row> ExecuteReader(string connectionString, string commandText)
        {
            using (ExcelConnection connection = new ExcelConnection(connectionString))
            {
                connection.Open();
                return ExecuteReader(connection, commandText);
            }
        }

        public static IEnumerator<Row> ExecuteReader(ExcelConnection connection, string commandText)
        {
            ExcelCommand command = new ExcelCommand(connection, commandText);
            return ExecuteReader(command);
        }

        public static IEnumerator<Row> ExecuteReader(ExcelTransaction transaction, string commandText)
        {
            ExcelCommand command = new ExcelCommand(transaction, commandText);
            return ExecuteReader(command);
        }

        public static IEnumerator<Row> ExecuteReader(ExcelCommand command)
        {
            return command.ExecuteReader();
        }
    }
}
